<template>
	<view class="orders">
		<view class="header">
			<view class="tabs">
				<view class="tabs-item" v-for="(item,index) in tabsList" :key="index"
					:class="current===index ? 'active' :''" @click="tabsClick(index)">{{item.name}}</view>
			</view>

		</view>
		<view class="order">
			<scroll-view class="scroll-view" scroll-x="true" @scroll="scroll" >
				<view id="demo1" class="orders-list d-flex flex-column w-100" style="padding: 20rpx; padding-bottom: 0;"
					v-if="not_paying!=null">


				
				<view class="not_paying_item" style="margin-bottom: 30rpx;" v-for="(item,index) in list"
					:key="index">
					<list-cell :hover="false">
						<view class="w-100 d-flex align-items-center">
							<view class="flex-fill d-flex flex-column">
								<view class="font-size-lg text-color-base" style="margin-bottom: 20rpx;">
									{{ item.orderAddress }}
								</view>
								<view class="font-size-sm text-color-assist">订单编号：{{ item.orderNumber }}</view>
							</view>
				
						</view>
					</list-cell>
					<list-cell :hover="false" last>
						<view class="w-100 d-flex flex-column">
							<view class="w-100 text-truncate font-size-lg text-color-base"
								style="margin-bottom: 20rpx;">
								
							</view>
							<view class="d-flex justify-content-between align-items-center"
								style="margin-bottom: 30rpx;">
								<view class="font-size-sm text-color-assist">
									{{ item.orderCreateTime }}
								</view>
				
								<view class="d-flex font-size-sm text-color-base align-items-center">
									<view class="font-size-lg text-color-primary" v-if="item.orderState===0">
										已支付
									</view>
									<view class="font-size-lg text-color-primary" v-if="item.orderState===1">
										待付款	
									</view>
									<view class="font-size-lg text-color-primary" v-if="item.orderState===2">
										已取消
									</view>
									<view class="font-size-lg text-color-primary" v-if="item.orderState===3">
										已退款
									</view>
									<view class="font-size-lg text-color-primary" v-if="item.orderState===4">
										待退款
									</view>
								</view>
							</view>
							<view class="d-flex align-items-center justify-content-end">
				
								<view v-if="item.orderState===0">
									<button type="primary" plain size="mini"
										@tap.stop="pay(item.orderNumber)">查看订单</button>
								</view>
								<view v-if="item.orderState===1">
									<button type="primary" plain size="mini"
										@tap.stop="pay(item.orderNumber)">去支付</button>
								</view>
								<view v-if="item.orderState===2">
									<button type="primary" plain size="mini"
										@tap.stop="pay(item.orderNumber)">查看订单</button>
								</view>
								<view v-if="item.orderState===3">
									<button type="primary" plain size="mini"
										@tap.stop="pay(item.orderNumber)">查看订单</button>
								</view>
								<view v-if="item.orderState===4">
									<button type="primary" plain size="mini"
										@tap.stop="pay(item.orderNumber)">查看订单</button>
								</view>
							</view>
						</view>
					</list-cell>
				</view>

		</view>
		</scroll-view>
	</view>
	</view>
</template>

<script>
	import listCell from '@/components/list-cell/list-cell'
	import { mapState, mapMutations } from "vuex";
	export default {
		components: {
			listCell
		},
		data() {
			return {
				tabsList: [{
						id: 0,
						name: "待付款"
					},
					{
						id: 1,
						name: "全部订单"
					}
				],
				current: 0,
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				
				not_paying: null,
				completed: null,
				list: null
			}
		},
		computed: {
			...mapState(["openid"]),
			
		},
		onLoad() {
			this.tabsClick();
		},
		onShow() {
			this.getOrderList()
		},
		methods: {
			tabsClick(index) {
				this.current = index
				if (index === 0) {
					this.list = this.not_paying
					return
				}
				if (index === 1) {
					this.list = this.completed
					return
				}
			},
			scroll() {
				this.old.scrollTop = e.detail.scrollTop
			},
			getOrderList() {
				let opt = {
					url: "/order/getOrderList",
					method: "get",
				}
				let param = {
					openid: this.openid
				}
				this.$req.httpRequest(opt, param).then(res => {
					// console.log(res)
					this.not_paying = res.data.data.not_paying
					this.completed = res.data.data.completed
					if (this.not_paying.length === 0) {
						this.current = 1
						this.list = this.completed
					} else {
						this.list = this.not_paying
					}
				})
			},
			pay(item) {
				uni.navigateTo({
					url: "/pages/orders/detail?isFriend=true&orderNumber=" + item,
				})
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.orders {
		width: 100%;

		.header {
			height: 80rpx;
			width: 100%;
			background-color: rgb(255, 255, 255);

			.tabs {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 100%;
				height: 80rpx;

				.tabs-item {
					display: flex;
					justify-content: center;
					align-items: center;
					margin: 120rpx;
					height: 100%;

				}
			}
		}

		.order {
			width: 100%;
			margin-top: 20rpx;
			margin-bottom: 50rpx;

			.scroll-view {
				white-space: nowrap;
				display: flex;
				width: 100%;

				.orders-list {
					width: 100%;
					height: 100%;
					display: inline-block;

					.not_paying_item {
						width: 100%;

					}

				}

				.uni-bg-green {
					width: 100%;
					height: 100%;
					display: inline-block;

					.completed-item {
						width: 100%;

					}
				}
			}
		}
	}

	.active {
		border-bottom: 5rpx solid red;
	}
</style>
